import 'package:efood_multivendor/data/model/response/campaign_filter_model.dart';

class ConfigModel {
  String? businessName;
  String? logo;
  String? address;
  String? phone;
  String? email;
  BaseUrls? baseUrls;
  String? currencySymbol;
  bool? cashOnDelivery;
  bool? digitalPayment;
  String? termsAndConditions;
  String? privacyPolicy;
  String? aboutUs;
  String? country;
  DefaultLocation? defaultLocation;
  String? appUrlAndroid;
  String? appUrlIos;
  bool? customerVerification;
  bool? orderDeliveryVerification;
  String? currencySymbolDirection;
  String? appMinimumVersionAndroid;
  String? appMinimumVersionIos;
  double? perKmShippingCharge;
  double? minimumShippingCharge;
  double? freeDeliveryOver;
  bool? demo;
  bool? maintenanceMode;
  int? popularFood;
  int? popularRestaurant;
  int? mostReviewedFoods;
  int? newRestaurant;
  String? orderConfirmationModel;
  bool? showDmEarning;
  bool? canceledByDeliveryman;
  bool? canceledByRestaurant;
  String? timeformat;
  bool? toggleVegNonVeg;
  bool? toggleDmRegistration;
  bool? toggleRestaurantRegistration;
  List<SocialLogin>? socialLogin;
  int? minimumProductPrice;
  int? maximumProductPrice;
  bool? rainWeather;
  UserCancellationModel? userCancellationReason;
  int? emergencyMode;
  String? emergencyMsgTitle;
  String? emergencyMsgBody;
  int? driverLanguagePreferenceFee;
  String? deliveryServiceChargeType;
  double? deliveryServiceChargeAmount;
  bool? isWalletActive;
  int? deadzoneAvailableOrder;
  List<int>? deliveryManTips;
  String? loginTip;
  String? guestTip;
  String? repeatedOrderTip;
  int? limitPerItemValue;
  String? limitPerItemTip;
  List<PaymentMethodModel>? paymentMethodModel;
  bool? callOnArrival;
  CampaignFilter? campaignFilters;
  int? defaultCampaignFilter;
  bool? isAddressChangeAllowed;
  bool? digitalPaymentCashback;

  ConfigModel({
    this.businessName,
    this.logo,
    this.address,
    this.phone,
    this.email,
    this.baseUrls,
    this.currencySymbol,
    this.cashOnDelivery,
    this.digitalPayment,
    this.termsAndConditions,
    this.privacyPolicy,
    this.aboutUs,
    this.country,
    this.defaultLocation,
    this.appUrlAndroid,
    this.appUrlIos,
    this.customerVerification,
    this.orderDeliveryVerification,
    this.currencySymbolDirection,
    this.appMinimumVersionAndroid,
    this.appMinimumVersionIos,
    this.perKmShippingCharge,
    this.minimumShippingCharge,
    this.freeDeliveryOver,
    this.demo,
    this.maintenanceMode,
    this.popularFood,
    this.popularRestaurant,
    this.mostReviewedFoods,
    this.newRestaurant,
    this.orderConfirmationModel,
    this.showDmEarning,
    this.canceledByDeliveryman,
    this.canceledByRestaurant,
    this.timeformat,
    this.toggleVegNonVeg,
    this.toggleDmRegistration,
    this.toggleRestaurantRegistration,
    this.socialLogin,
    this.rainWeather,
    this.userCancellationReason,
    this.emergencyMode,
    this.emergencyMsgTitle,
    this.emergencyMsgBody,
    this.driverLanguagePreferenceFee,
    this.deliveryServiceChargeType,
    this.deliveryServiceChargeAmount,
    this.isWalletActive,
    this.deadzoneAvailableOrder,
    this.deliveryManTips,
    this.loginTip,
    this.guestTip,
    this.repeatedOrderTip,
    this.limitPerItemValue,
    this.limitPerItemTip,
    this.paymentMethodModel,
    this.callOnArrival,
    this.campaignFilters,
    this.defaultCampaignFilter,
    this.isAddressChangeAllowed,
    this.digitalPaymentCashback,
    int? minimumProductPrice,
    int? maximumProductPrice,
  });

  factory ConfigModel.fromJson(Map<String, dynamic> json) {
    return ConfigModel(
      businessName: json['business_name'] as String?,
      logo: json['logo'] as String?,
      address: json['address'] as String?,
      phone: json['phone'] as String?,
      email: json['email'] as String?,
      baseUrls: json['base_urls'] != null
          ? BaseUrls.fromJson(json['base_urls'])
          : null,
      currencySymbol: json['currency_symbol'] as String?,
      cashOnDelivery: json['cash_on_delivery'] as bool?,
      digitalPayment: json['digital_payment'] as bool?,
      termsAndConditions: json['terms_and_conditions'] as String?,
      privacyPolicy: json['privacy_policy'] as String?,
      aboutUs: json['about_us'] as String?,
      country: json['country'] as String?,
      defaultLocation: json['default_location'] != null
          ? DefaultLocation.fromJson(json['default_location'])
          : null,
      appUrlAndroid: json['app_url_android'] as String?,
      appUrlIos: json['app_url_ios'] as String?,
      customerVerification: json['customer_verification'] as bool?,
      orderDeliveryVerification: json['order_delivery_verification'] as bool?,
      currencySymbolDirection: json['currency_symbol_direction'] as String?,
      appMinimumVersionAndroid: json['app_minimum_version_android'] as String?,
      appMinimumVersionIos: json['app_minimum_version_ios'] as String?,
      perKmShippingCharge: (json['per_km_shipping_charge'] as num?)?.toDouble(),
      minimumShippingCharge:
          (json['minimum_shipping_charge'] as num?)?.toDouble(),
      freeDeliveryOver: (json['free_delivery_over'] as num?)?.toDouble(),
      demo: json['demo'] as bool?,
      maintenanceMode: json['maintenance_mode'] as bool?,
      popularFood: json['popular_food'] as int?,
      popularRestaurant: json['popular_restaurant'] as int?,
      newRestaurant: json['new_restaurant'] as int?,
      mostReviewedFoods: json['most_reviewed_foods'] as int?,
      orderConfirmationModel: json['order_confirmation_model'] as String?,
      showDmEarning: json['show_dm_earning'] as bool?,
      canceledByDeliveryman: json['canceled_by_deliveryman'] as bool?,
      canceledByRestaurant: json['canceled_by_restaurant'] as bool?,
      timeformat: json['timeformat'] as String?,
      toggleVegNonVeg: json['toggle_veg_non_veg'] as bool?,
      toggleDmRegistration: json['toggle_dm_registration'] as bool?,
      toggleRestaurantRegistration:
          json['toggle_restaurant_registration'] as bool?,
      socialLogin: (json['social_login'] as List?)
          ?.map((v) => SocialLogin.fromJson(v))
          .toList(),
      minimumProductPrice: json['minimum_product_price'] as int?,
      maximumProductPrice: json['maximum_product_price'] as int?,
      rainWeather: json['bad_weather'] as bool?,
      userCancellationReason: json['user_cancellation_reasons'] != null
          ? UserCancellationModel.fromJson(json['user_cancellation_reasons'])
          : null,
      emergencyMode: json['emergency_mode'] as int?,
      emergencyMsgTitle: json['emergency_msg_title'] as String?,
      emergencyMsgBody: json['emergency_msg_body'] as String?,
      driverLanguagePreferenceFee:
          int.tryParse(json['language_preference_fee']?.toString() ?? ''),
      deliveryServiceChargeType:
          json['delivery_service_charge_type'] as String?,
      deliveryServiceChargeAmount:
          num.tryParse(json['delivery_service_charge_amount'].toString())
              ?.toDouble(),
      isWalletActive: json['customer_wallet_payment'] as bool?,
      deadzoneAvailableOrder: json['dead_zone_available_order'] as int?,
      deliveryManTips: (json['delivery_man_tips'] as List?)?.cast<int>(),
      loginTip: json['login_tip'] as String?,
      guestTip: json['guest_order_tip'] as String?,
      repeatedOrderTip: json['repeat_order_tip'] as String?,
      limitPerItemValue: json['limit_per_item'] as int?,
      limitPerItemTip: json['limit_per_item_tip'] as String?,
      paymentMethodModel: (json['payment_methods'] as List?)
          ?.map((v) => PaymentMethodModel.fromJson(v))
          .toList(),
      callOnArrival: json['call_on_arrival'] as bool?,
      campaignFilters: json['campaign_filter'] != null
          ? (json['campaign_filter'] is Map<String, dynamic>
              ? CampaignFilter.fromJson(json['campaign_filter'])
              : CampaignFilter(filters: {}))
          : null,
      defaultCampaignFilter: json['default_campaign_filter'] as int?,
      isAddressChangeAllowed: json['is_address_change_allowed'] as bool?,
      digitalPaymentCashback: json['digital_payment_cashback'] as bool?,
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['business_name'] = businessName;
    data['logo'] = logo;
    data['address'] = address;
    data['phone'] = phone;
    data['email'] = email;
    if (baseUrls != null) data['base_urls'] = baseUrls!.toJson();
    data['currency_symbol'] = currencySymbol;
    data['cash_on_delivery'] = cashOnDelivery;
    data['digital_payment'] = digitalPayment;
    data['terms_and_conditions'] = termsAndConditions;
    data['privacy_policy'] = privacyPolicy;
    data['about_us'] = aboutUs;
    data['country'] = country;
    if (defaultLocation != null)
      data['default_location'] = defaultLocation!.toJson();
    data['app_url_android'] = appUrlAndroid;
    data['app_url_ios'] = appUrlIos;
    data['customer_verification'] = customerVerification;
    data['order_delivery_verification'] = orderDeliveryVerification;
    data['currency_symbol_direction'] = currencySymbolDirection;
    data['app_minimum_version_android'] = appMinimumVersionAndroid;
    data['app_minimum_version_ios'] = appMinimumVersionIos;
    data['per_km_shipping_charge'] = perKmShippingCharge;
    data['minimum_shipping_charge'] = minimumShippingCharge;
    data['free_delivery_over'] = freeDeliveryOver;
    data['demo'] = demo;
    data['maintenance_mode'] = maintenanceMode;
    data['popular_food'] = popularFood;
    data['popular_restaurant'] = popularRestaurant;
    data['new_restaurant'] = newRestaurant;
    data['most_reviewed_foods'] = mostReviewedFoods;
    data['order_confirmation_model'] = orderConfirmationModel;
    data['show_dm_earning'] = showDmEarning;
    data['canceled_by_deliveryman'] = canceledByDeliveryman;
    data['canceled_by_restaurant'] = canceledByRestaurant;
    data['timeformat'] = timeformat;
    data['toggle_veg_non_veg'] = toggleVegNonVeg;
    data['toggle_dm_registration'] = toggleDmRegistration;
    data['toggle_restaurant_registration'] = toggleRestaurantRegistration;
    if (socialLogin != null)
      data['social_login'] = socialLogin!.map((v) => v.toJson()).toList();
    data['minimum_product_price'] = minimumProductPrice;
    data['maximum_product_price'] = maximumProductPrice;
    data['bad_weather'] = rainWeather;
    if (userCancellationReason != null)
      data['user_cancellation_reasons'] = userCancellationReason!.toJson();
    data['emergency_mode'] = emergencyMode;
    data['emergency_msg_title'] = emergencyMsgTitle;
    data['emergency_msg_body'] = emergencyMsgBody;
    data['language_preference_fee'] = driverLanguagePreferenceFee?.toString();
    data['delivery_service_charge_type'] = deliveryServiceChargeType;
    data['delivery_service_charge_amount'] = deliveryServiceChargeAmount;
    data['dead_zone_available_order'] = deadzoneAvailableOrder;
    data['login_tip'] = loginTip;
    data['guest_order_tip'] = guestTip;
    data['limit_per_item'] = limitPerItemValue;
    data['limit_per_item_tip'] = limitPerItemTip;
    data['call_on_arrival'] = callOnArrival;
    if (campaignFilters != null)
      data['campaign_filter'] = campaignFilters!.toJson();
    data['default_campaign_filter'] = defaultCampaignFilter;
    data['is_address_change_allowed'] = isAddressChangeAllowed;
    data['digital_payment_cashback'] = digitalPaymentCashback;
    return data;
  }
}

class BaseUrls {
  String? productImageUrl;
  String? customerImageUrl;
  String? bannerImageUrl;
  String? categoryImageUrl;
  String? reviewImageUrl;
  String? notificationImageUrl;
  String? restaurantImageUrl;
  String? restaurantCoverPhotoUrl;
  String? deliveryManImageUrl;
  String? chatImageUrl;
  String? campaignImageUrl;
  String? businessLogoUrl;

  BaseUrls({
    this.productImageUrl,
    this.customerImageUrl,
    this.bannerImageUrl,
    this.categoryImageUrl,
    this.reviewImageUrl,
    this.notificationImageUrl,
    this.restaurantImageUrl,
    this.restaurantCoverPhotoUrl,
    this.deliveryManImageUrl,
    this.chatImageUrl,
    this.campaignImageUrl,
    this.businessLogoUrl,
  });

  factory BaseUrls.fromJson(Map<String, dynamic> json) {
    return BaseUrls(
      productImageUrl: json['product_image_url'] as String?,
      customerImageUrl: json['customer_image_url'] as String?,
      bannerImageUrl: json['banner_image_url'] as String?,
      categoryImageUrl: json['category_image_url'] as String?,
      reviewImageUrl: json['review_image_url'] as String?,
      notificationImageUrl: json['notification_image_url'] as String?,
      restaurantImageUrl: json['restaurant_image_url'] as String?,
      restaurantCoverPhotoUrl: json['restaurant_cover_photo_url'] as String?,
      deliveryManImageUrl: json['delivery_man_image_url'] as String?,
      chatImageUrl: json['chat_image_url'] as String?,
      campaignImageUrl: json['campaign_image_url'] as String?,
      businessLogoUrl: json['business_logo_url'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['product_image_url'] = productImageUrl;
    data['customer_image_url'] = customerImageUrl;
    data['banner_image_url'] = bannerImageUrl;
    data['category_image_url'] = categoryImageUrl;
    data['review_image_url'] = reviewImageUrl;
    data['notification_image_url'] = notificationImageUrl;
    data['restaurant_image_url'] = restaurantImageUrl;
    data['restaurant_cover_photo_url'] = restaurantCoverPhotoUrl;
    data['delivery_man_image_url'] = deliveryManImageUrl;
    data['chat_image_url'] = chatImageUrl;
    data['campaign_image_url'] = campaignImageUrl;
    data['business_logo_url'] = businessLogoUrl;
    return data;
  }
}

class DefaultLocation {
  String? lat;
  String? lng;

  DefaultLocation({this.lat, this.lng});

  factory DefaultLocation.fromJson(Map<String, dynamic> json) {
    return DefaultLocation(
      lat: json['lat'] as String?,
      lng: json['lng'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['lat'] = lat;
    data['lng'] = lng;
    return data;
  }
}

class SocialLogin {
  String? loginMedium;
  bool? status;

  SocialLogin({this.loginMedium, this.status});

  factory SocialLogin.fromJson(Map<String, dynamic> json) {
    return SocialLogin(
      loginMedium: json['login_medium'] as String?,
      status: json['status'] as bool?,
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['login_medium'] = loginMedium;
    data['status'] = status;
    return data;
  }
}

class UserCancellationModel {
  UserCancellationAmharicModel? userCancellationAmharic;
  UserCancellationEnglishModel? userCancellationEnglishModel;
  UserCancellationChineseModel? userCancellationChineseModel;

  UserCancellationModel({
    this.userCancellationAmharic,
    this.userCancellationEnglishModel,
    this.userCancellationChineseModel,
  });

  factory UserCancellationModel.fromJson(Map<String, dynamic> json) {
    return UserCancellationModel(
      userCancellationAmharic: json['amharic'] != null
          ? UserCancellationAmharicModel.fromJson(json['amharic'])
          : null,
      userCancellationEnglishModel: json['english'] != null
          ? UserCancellationEnglishModel.fromJson(json['english'])
          : null,
      userCancellationChineseModel: json['chinese'] != null
          ? UserCancellationChineseModel.fromJson(json['chinese'])
          : null,
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (userCancellationAmharic != null)
      data['amharic'] = userCancellationAmharic!.toJson();
    if (userCancellationEnglishModel != null)
      data['english'] = userCancellationEnglishModel!.toJson();
    if (userCancellationChineseModel != null)
      data['chinese'] = userCancellationChineseModel!.toJson();
    return data;
  }
}

class UserCancellationAmharicModel {
  List<dynamic>? amharicIds;
  List<dynamic>? amharicBody;

  UserCancellationAmharicModel({this.amharicIds, this.amharicBody});

  factory UserCancellationAmharicModel.fromJson(Map<String, dynamic> json) {
    final model = UserCancellationAmharicModel();
    if (json.isNotEmpty) {
      model.amharicIds = json.entries.map((e) => e.key).toList();
      model.amharicBody = json.entries.map((e) => e.value).toList();
    }
    return model;
  }

  Map<String, dynamic> toJson() => {};
}

class UserCancellationEnglishModel {
  List<dynamic>? englishIds;
  List<dynamic>? englishBody;

  UserCancellationEnglishModel({this.englishIds, this.englishBody});

  factory UserCancellationEnglishModel.fromJson(Map<String, dynamic> json) {
    final model = UserCancellationEnglishModel();
    if (json.isNotEmpty) {
      model.englishIds = json.entries.map((e) => e.key).toList();
      model.englishBody = json.entries.map((e) => e.value).toList();
    }
    return model;
  }

  Map<String, dynamic> toJson() => {};
}

class UserCancellationChineseModel {
  List<dynamic>? chineseIds;
  List<dynamic>? chineseBody;

  UserCancellationChineseModel({this.chineseIds, this.chineseBody});

  factory UserCancellationChineseModel.fromJson(Map<String, dynamic> json) {
    final model = UserCancellationChineseModel();
    if (json.isNotEmpty) {
      model.chineseIds = json.entries.map((e) => e.key).toList();
      model.chineseBody = json.entries.map((e) => e.value).toList();
    }
    return model;
  }

  Map<String, dynamic> toJson() => {};
}

class PaymentMethodModel {
  String? name;
  String? logo;
  String? text;
  bool? cashbackEnabled;

  PaymentMethodModel({this.name, this.logo, this.text, this.cashbackEnabled});

  factory PaymentMethodModel.fromJson(Map<String, dynamic> json) {
    return PaymentMethodModel(
      name: json['name'] as String?,
      logo: json['logo'] as String?,
      text: json['text'] as String?,
      cashbackEnabled: json['cashback'] as bool?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'logo': logo,
      'text': text,
      'cashback': cashbackEnabled,
    };
  }

  static List<PaymentMethodModel> fromJsonList(List<dynamic> jsonList) {
    return jsonList.map((json) => PaymentMethodModel.fromJson(json)).toList();
  }
}
